﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class HeroCtrl : MonoBehaviour {
    public float JumpForce;
    private bool OnGround;
    void Start () {
		
	}
	
	void Update () {

        if (Input.GetKeyDown(KeyCode.Space)) {
            if(OnGround)
            transform.GetComponent<Rigidbody2D>().AddForce(new Vector2(0, JumpForce));
        }

	}
    void LateUpdate() {
        OnGround = false;

    }

    void OnCollisionStay2D(Collision2D other) {
        if (other.gameObject.tag == "ground")
            OnGround = true;
    }

}
